package com.auerdi.ui.fragment.a_home.adapter.delegate;

import android.app.Activity;
import android.view.View;
import android.widget.ImageView;

import com.auerdi.GlideApp;
import com.auerdi.R;
import com.auerdi.ui.detail.ADProductDetailFragment;
import com.auerdi.ui.fragment.a_home.adapter.items.HomeItemsBean;
import com.example.egghttp.EggLog.L;
import com.example.egghttp.retrofit.beans.goods.Product;
import com.squareup.picasso.Picasso;
import com.zhy.adapter.recyclerview.base.ItemViewDelegate;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import me.yokeyword.eventbusactivityscope.EventBusActivityScope;

/**
 * Created by zhy on 16/6/22.
 */
public class EisGoodWorldList implements ItemViewDelegate<HomeItemsBean> {

    @Override
    public int getItemViewLayoutId() {
        return R.layout.item_home_world;
    }
//    public int getItemViewLayoutId() {
//        return R.layout.item_home_e_goodwordlist;
//    }

    @Override
    public boolean isForViewType(HomeItemsBean item, int position) {

        return item.getRouter().equals(getClass().getSimpleName());
    }

    @Override
    public void convert(ViewHolder viewHolder, HomeItemsBean item, int position) {
        Product product = (Product) item.getItem();


//        recy_world

        ImageView imgView = viewHolder.getView(R.id.img);
        ImageView gPic = viewHolder.getView(R.id.gpic);
        viewHolder.setText(R.id.title, product.getTitle());
        viewHolder.setText(R.id.gname, product.getBnProductGuojiaName());
        viewHolder.setText(R.id.stitle, product.getShareTitle());
        viewHolder.setText(R.id.num, "已团" + product.getPayCount() + "件");


        viewHolder.setText(R.id.apri, "¥" + product.getSuccessPrice());
        viewHolder.setText(R.id.bpri, "¥" + product.getMarkPrice());


//        Picasso.get().load(product.getImg()).error(R.mipmap.logo).placeholder(R.mipmap.logo).resize(750, 352).centerCrop().into(imgView);
        Picasso.get().load(product.getBnProductGuojia()).error(R.mipmap.epta).placeholder(R.mipmap.epta).fit().centerInside().into(gPic);

        GlideApp.with(viewHolder.getConvertView().getContext())
                .load(product.getLunboImg())
                .placeholder(R.mipmap.eptb)
                .error(R.mipmap.eptb)
                .centerCrop()
                .into(imgView);


        viewHolder.getConvertView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                L.d("hcia", "product:" + product);


                EventBusActivityScope.getDefault((Activity) viewHolder.getConvertView().getContext()).post(ADProductDetailFragment.newInstance(product));


            }
        });


    }
}
